var app = getApp()
Page({
  
  /**
  * 页面的初始数据
  */
  data: {
  classfiySelect: "",
  unitphone:"",
  leftText: [{
  id: "01",
  text1: "未就诊",
  },
  {
  id: "02",
  text1: "已就诊",
  },
  ],
  rightData: [{
  id: "01",
  title:"未就诊",
  frist: [],
  },
  {
    id: "02",
    title:"已就诊",
    frist: [
    ],
  },
    
  
  ],
  },
  /**
  * 生命周期函数--监听页面加载
  */
  onLoad: function(options) {
  this.setData({
  classfiySelect: this.data.leftText[0].id
  })
  this.setData({
    unitphone:app.globalData.unitphone
  })
  var that = this;
    wx.request({
      url:  getApp().globalData.url+'patientMyOrder', // 仅为示例，并非真实的接口地址
      method: 'GET',
      data: {
        unitphone:app.globalData.unitphone,
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 默认值
      },
      success(res) {
       console.log(res.data)
       let fi={};
       let first=[];
        for(let j=0;j<2;j++)
        {
          for(let i=0;i<res.data.length;i++)
          {
            if(res.data[i].orderForm.progress==that.data.leftText[j].text1)
            {
              var times="";
              var doctorRank0="";
              var doctorName0 ="";
              var bookId="";//预约ID
                bookId=res.data[i].orderForm.bookId;
                doctorName0=res.data[i].doctorName;
                times=res.data[i].orderForm.bootDate+" "+res.data[i].orderForm.bootTime;
                doctorRank0=res.data[i].doctorRank;
                fi ={"text":doctorName0,"money":doctorRank0,"times":times,"bookid":bookId};
                first.push(fi);
            }
          }
         if(j==0)
         {
          that.setData({
            "rightData[0].frist":first
          })
         }
         else if(j==1)
         {
          that.setData({
            "rightData[1].frist":first
          })
         }
         
         first=[];
        }
        console.log(that.data.rightData)

      },fail:(res) => {
        wx.showToast({
          title: '网络连接失败，请重新尝试',
          icon:'none'
        })
    }})
  },
   
  /**
  * 生命周期函数--监听页面初次渲染完成
  */
  onReady: function() {
   
  },
   
  /**
  * 生命周期函数--监听页面显示
  */
  onShow: function() {
   
  },
   
  /**
  * 生命周期函数--监听页面隐藏
  */
  onHide: function() {
   
  },
   
  /**
  * 生命周期函数--监听页面卸载
  */
  onUnload: function() {
   
  },
   
  /**
  * 页面相关事件处理函数--监听用户下拉动作
  */
  onPullDownRefresh: function() {
   
  },
   
  /**
  * 页面上拉触底事件的处理函数
  */
  onReachBottom: function() {
   
  },
   
  /**
  * 用户点击右上角分享
  */
  onShareAppMessage: function() {
   
  },
  //滚动触发
  scroll: function(e) {
  var scrollTop = e.detail.scrollTop,
  h = 0,
  classfiySelect;
  var that = this;
  that.data.leftText.forEach(function(clssfiy, i) {
  var _h =26 + that.length(clssfiy['id'])*102;
  if (scrollTop >= h){
  classfiySelect = clssfiy['id'];
  }
  h +=_h;
  console.log(h);
  })
  that.setData({
  classfiySelect: classfiySelect,
  })
  },
  //求每一栏高度
  length: function(e) {
  var that = this;
  var rightData = that.data.rightData;
  for (var i = 0; i < rightData.length; i++) {
  if(rightData[i]['id']==e){
  return rightData[i]['frist'].length;
   
  }
  }
  },
  //点击左边事件
  left_list: function(e) {
  var that = this;
  var l_id = e.currentTarget.dataset.id;
  that.setData({
  rigId: l_id,
  })
  },
  //跳转详情界面
  togood:function(e){
    var chooseDoctor = e.target.dataset.index;
    console.log(chooseDoctor)
    app.globalData.doctorId=chooseDoctor
    console.log(app.globalData.doctorId)
    var that = this;
    wx.request({
      url:  getApp().globalData.url+'patientOrderView2', // 仅为示例，并非真实的接口地址
      method: 'GET',
      data: {
          doctorId:this.data.doctorId,
          unitphone:getApp().globalData.unitphone
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 默认值
      },
      success(res) {
        wx.switchTab({
          url: '../mainpages/mainpage/mainpage',
        })
      },
      fail(res){
        wx.showToast({
          title: '网络连接失败，请重新尝试',
          icon:'none'
        })
      }
    })
  }
   
})
 